myChart_kaiguan = echarts.init(document.getElementById('kaiguan'));
// 初始状态为开启
isOn = false;
function updateChart() {
    var option_kaiguan = {
        title: {
            text: '蜂鸣器开关',
            textStyle: { fontSize: '21px', color: '#ccc' },
            top: 12
        },
        graphic: {
            type: 'text',
            left: 'center',
            top: 'center',
            style: {
                text: isOn ? '开' : '关',
                fill: isOn ? '#67C23A' : '#F56C6C',
                fontSize: 28,
                fontWeight: 'bold'
            }
        },
        series: [{
            type: 'pie',
            radius: ['55%', '70%'],
            silent: false,
            itemStyle: { borderColor: '#fff', borderWidth: 2 },
            data: [
                { value: isOn ? 1 : 0, itemStyle: { color: '#67C23A' } },
                { value: isOn ? 0 : 1, itemStyle: { color: '#F56C6C' } }
            ]
        }]
    };
    myChart_kaiguan.setOption(option_kaiguan, true);
}

myChart_kaiguan.off('click');
myChart_kaiguan.on('click', function () {
    isOn = !isOn;
    updateChart();
    console.log(isOn);
    sendKaiguanDate(isOn)
});

updateChart();

function sendKaiguanDate(zhuangtai) {
    // 向给定ID的用户发起请求
    axios.get('/mybatisdemo/iot/kaiguan?b=' + zhuangtai)
        .then(function (response) {
            // 处理成功情况
            var msg = response.data;
            console.log(msg);

        })
        .catch(function (error) {
            // 处理错误情况
            console.log(error);
        })
        .finally(function () {
            // 总是会执行
        });
}